//
//  SingleViewController.m
//  海角音乐
//
//  Created by dllo on 15/8/11.
//  Copyright (c) 2015年 杨元石. All rights reserved.
//

#import "SingleViewController.h"
#import "DEFINE.h"
@implementation SingleViewController 

- (void)dealloc
{
    [_tableView release];
    [_dataArr release];
    [_reDetailModel release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // 背景图片
    UIImageView *back_image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    back_image.image = [UIImage imageNamed:@"素材落日"];
    [back_image setContentScaleFactor:[[UIScreen mainScreen] scale]];
    back_image.contentMode =  UIViewContentModeScaleAspectFill;
    back_image.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    back_image.clipsToBounds  = YES;
    [self.view addSubview:back_image];
    
    self.view.backgroundColor = [UIColor clearColor];
    UILabel *ss = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
    ss.text = @"当前播放列表";
    ss.font = [UIFont boldSystemFontOfSize:20];
    ss.textColor = [UIColor brownColor];
    [self.view addSubview:ss];

    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, SCREEN_WIDTH, SCREEN_HEIGHT-50) style:UITableViewStylePlain];
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.view addSubview:self.tableView];
    [_tableView release];
    
    UIView *bar = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-50, SCREEN_WIDTH, 50)];
    UIButton *PPP = [UIButton buttonWithType:UIButtonTypeCustom];
    
    CGFloat ppp_X = SCREEN_WIDTH*0.8533333;
    CGFloat ppp_Y = SCREEN_WIDTH*0.026666;
    CGFloat ppp_width = SCREEN_WIDTH*0.106667;
    CGFloat ppp_height= SCREEN_WIDTH*0.08;
    
    PPP.frame = CGRectMake(ppp_X, ppp_Y, ppp_width, ppp_height);
    [PPP setBackgroundImage:[UIImage imageNamed:@"iconfont-liebiao.png"] forState:0];
    [PPP addTarget:self action:@selector(listAction) forControlEvents:UIControlEventTouchUpInside];
    [bar addSubview:PPP];
    [self.view addSubview:bar];
    
       
    // Do any additional setup after loading the view.
}


- (void)listAction
{
    [self dismissViewControllerAnimated:YES completion:nil];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   
    return self.dataArr.count;
   
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *cellID = @"cell";
    
    ReDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    if (cell == NO) {
        
        cell = [[ReDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    
    if (self.dataArr.count > indexPath.row) {
        
        ReDetailModel *de = [self.dataArr objectAtIndex:indexPath.row];
        [cell getDataForCell:de];
        cell.textLabel.text = [NSString stringWithFormat:@"%ld", indexPath.row+1];
    }
    
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
   
    return SCREEN_WIDTH*0.266667;
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    ReDetailModel *reDetailmodel = [self.dataArr objectAtIndex:indexPath.row];
    DanLiPlayer *Dan = [DanLiPlayer shareHandleDanLiPlayer:CGRectZero];
    Dan.reDetailModel = reDetailmodel;
    [self playMusicWithMusicModel:reDetailmodel indexPath:indexPath];
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    [nc postNotificationName:@"player" object:nil];

    
    
    
}
// 播放方法
- (void)playMusicWithMusicModel:(ReDetailModel *)ReDetailModel indexPath:(NSIndexPath *)path
{
    
    NSDictionary *dic = [ReDetailModel.audition_list objectAtIndex:1];
    
    NSString *url_string = [dic objectForKey:@"url"];
    
    STKAudioPlayer *player = [SinglePlayer shareHandleSinglePlayer];
    
    [player play:url_string];
    

}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
